package com.dotflat.check.domain.C;

import lombok.Data;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.io.ByteArrayInputStream;
import java.util.List;

@Data
@XmlRootElement(name="GetGuardianListInfo2")  // 父节点名称
@XmlAccessorType(XmlAccessType.FIELD) //定义这个类中的何种类型需要映射到XML
public class GetGuardianListInfo2 {

    @XmlElement(name = "kgId")
    Integer kgId;
    @XmlElement(name = "modifyTime")
    String modifyTime;


    public static GetGuardianListInfo2 dom4jXml(String interfaceData) throws Exception{
        List<Element> elementList = null;
        GetGuardianListInfo2 beanAlarmHisList = null;

        try {
            SAXReader sr = new SAXReader();
            Document document = sr.read(new ByteArrayInputStream(interfaceData.getBytes()));

            Element root = document.getRootElement();
            elementList = root.elements();

        } catch (DocumentException e) {
            e.printStackTrace();
        }
        for (Element e : elementList) {
            // 解析标签下一级标签
            Element e1 = e.element("GetGuardianListInfo2");
            GetGuardianListInfo2 attendanceUser = new GetGuardianListInfo2();
            attendanceUser.setKgId(Integer.valueOf(e1.elementText("kgId")));
            attendanceUser.setModifyTime(e1.elementText("modifyTime"));
            return attendanceUser;
        }
        return null;
    }
}
